// pages/my/my.js
import {queryHistory,getUserInfo} from "../../api/index"
let app = getApp()
Page({
  data: {
    _title:"个人中心",
    studyTime:0,
    studyCount:0,
    userInfo:{},
    studyRcordList:[],
  },
  onLoad: function (options) {
    getApp().upTitle(this.data._title)
    if(app.globalData.userInfo){
      this.setData({
        userInfo:app.globalData.userInfo
      })
    }else{
      this.getInfo()
    }
  },
  onShow(){
    this.findHostiry()
  },
  getInfo(){
    let data = {
      token:app.globalData.token
    }
    getUserInfo(data).then(res=>{
      let {success,data} = res
      if(success){
        let {nickName,headPictureUrl} = data
        let userInfo = {
          nickName:nickName,
          avatarUrl:headPictureUrl
        }
        this.setData({
          userInfo:userInfo
        })
      }
    })
  },
findHostiry(){
  let data = {
    pageNum:0,
    pageSize:3,
    token:app.globalData.token
  }
  queryHistory(data).then(res=>{
    let {success,datalist} = res
    if(success){
      this.setData({
        studyRcordList:datalist
      })
    }
  })
},
  gotoPage:function(event){
    let url;
    if(event.currentTarget.dataset.id){
      getApp().gotoDetailsPage(event.currentTarget.dataset.url,event.currentTarget.dataset.id)
    }else{
      wx.navigateTo({
        url:event.currentTarget.dataset.url
      })
    }
    
  }
})